package com.graduation_design.modules.app.mq;

import com.graduation_design.modules.app.config.RabbitConfig;
import com.graduation_design.service.AppOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Slf4j
@Component
@RabbitListener(queues = RabbitConfig.ORDER_CANCEL_TTL_QUEUE)
public class CancelOrderReceiver {
    // 接收消息

    @Resource
    AppOrderService appOrderService;

    @RabbitListener(queues = RabbitConfig.ORDER_CANCEL_TTL_QUEUE)
    public void handle(Long orderId) {

        // 取消订单
        appOrderService.closeAdmin(orderId, "订单超时系统自动取消", 2L);
        log.info("正在处理超时订单：{}, 处理完毕！", orderId);
    }
}
